<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('系统管理员操作界面')"/>
</head>
<style type="text/css">

    @media screen and (max-width: 768px) {
        body {
            /*text-align:center;*/
            margin: 0px auto;
        }
        #pbid input{
            width: auto;
        }
    }

    /**电脑屏幕下显示***/
    @media screen and (min-width: 768px) {
        body {
            /*text-align:center;*/
            margin: 0px auto;
        }
        #xh{
            width: 150px;
        }
        #rq{
            width: 150px;
        }
        #bm{
            width: 150px;
        }
        #sbbh{
            width: 150px;
        }
        #gzyy{
            width: 150px;
        }
        #jjfa{
            width: 150px;
        }
        #whry{
            width: 150px;
        }
        #syry{
            width: 150px;
        }
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12 b-r">
            <form id="operlog-form">
                <div class="select-list">
                    <ul>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input class="time-input" id="kssj" name="kssj" placeholder="开始时间"
                                   type="text"/>
                            <span>-</span>
                            <input class="time-input" id="jssj" name="jssj" placeholder="结束时间"
                                   type="text"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" id="search_btn"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-10 b-r">
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-danger" id="remove" onclick="whjldy()">
                    <i class="fa fa-remove"></i> 维护记录打印
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table data-mobile-responsive="true" id="bootstrap-table"></table>
            </div>
        </div>
        <div class="col-sm-2" id="pbid" style="display: none">
            <h4>请选择打印的条目(已毫米为单位)</h4>
            <p style="display: none">标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题<input type="text" id="bt"></p>
            <p style="display: none">文&nbsp;&nbsp;&nbsp;&nbsp;件&nbsp;&nbsp;&nbsp;&nbsp;号<input type="text" id="wjh"></p>
            <p><input type="checkbox" id="xhbox" checked>序&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号<input type="text" id="xh" value="10mm"></p>
            <p><input type="checkbox" id="rqbox" checked>日&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;期<input type="text" id="rq" value="18mm"></p>
            <p><input type="checkbox" id="bmbox" checked>部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;门<input type="text" id="bm" value="18mm"></p>
            <p><input type="checkbox" id="sbbhbox" checked>设备编号<input type="text" id="sbbh" value="24mm"></p>
            <p><input type="checkbox" id="gzyybox" checked>故障原因<input type="text" id="gzyy" value="58mm"></p>
            <p><input type="checkbox" id="jjfabox" checked>解决方案<input type="text" id="jjfa" value="80mm"></p>
            <p><input type="checkbox" id="whrybox" checked>维护人员<input type="text" id="whry" value="21mm"></p>
            <p><input type="checkbox" id="syrybox" checked>使用人员<input type="text" id="syry" value="21mm"></p>
            <button type="submit" id="reset">数值重置</button>
            <br><span>每页打印条数<input type="text" id="linecount" value="25"></span>
        </div>
    </div>
</div>
<div class="container-div" style="display: none;">
    <div class="row">
        <!--<div class="col-sm-12 search-collapse">-->
        <!--<form id="operlog-form">-->
        <!--<div class="select-list">-->
        <!--<ul>-->
        <!--<li class="select-time">-->
        <!--<label>创建时间： </label>-->
        <!--<input class="time-input" id="kssj" name="kssj" placeholder="开始时间"-->
        <!--type="text"/>-->
        <!--<span>-</span>-->
        <!--<input class="time-input" id="jssj" name="jssj" placeholder="结束时间"-->
        <!--type="text"/>-->
        <!--</li>-->
        <!--<li>-->
        <!--<a class="btn btn-primary btn-rounded btn-sm" id="search_btn"><i-->
        <!--class="fa fa-search"></i>&nbsp;搜索</a>-->
        <!--</li>-->
        <!--</ul>-->
        <!--</div>-->
        <!--</form>-->
        <!--</div>-->
        <!--<div class="btn-group-sm" id="toolbar" role="group">-->
        <!--<a class="btn btn-danger" id="remove" onclick="whjldy()">-->
        <!--<i class="fa fa-remove"></i> 维护记录打印-->
        <!--</a>-->
        <!--</div>-->
        <!--<div class="col-sm-10 select-table table-striped">-->
        <!--<table data-mobile-responsive="true" id="bootstrap-table"></table>-->
        <!--</div>-->
        <!--隐藏的打印设备台账表格开始-->
        <div class="col-sm-12 select-table table-striped" id="divid_sbtz">
            <table class='table table-hover table-bordered' cellpadding='0' border='1' cellspacing='0'
                   id="tableid_sbtz">
                <thead>
                <tr style="font-size: 12pt;font-family: 微软雅黑">
                    <td align="center" id="xhtd" style="background-color: #99CCFF;width: 5%;">序号</td>
                    <td align="center" id="rqtd" style="background-color: #99CCFF;width: 5%">维护日期</td>
                    <td align="center" id="bmtd" style="background-color: #99CCFF;width: 5%">部门</td>
                    <td align="center" id="sbbhtd" style="background-color: #99CCFF;width: 5%">设备编号</td>
                    <td align="center" id="gzyytd" style="background-color: #99CCFF;width: 5%">故障原因</td>
                    <td align="center" id="jjfatd" style="background-color: #99CCFF;width: 5%">解决方案</td>
                    <td align="center" id="whrytd" style="background-color: #99CCFF;width: 5%">维护人员</td>
                    <td align="center" id="syrytd" style="background-color: #99CCFF;width: 5%">使用人员</td>
                    <td align="center" style="background-color: #99CCFF;width: 20mm">签字</td>
                </tr>
                </thead>
                <tbody id="tbody_id">
                </tbody>
            </table>
        </div>
    </div>
</div>
<div><input id="_pageNumber" type="hidden"></div>
<div><input id="_pageSize" type="hidden"></div>
<div th:replace="zdyyj :: myfooter"></div>
<th:block th:include="include :: footer"/>
<script th:src="@{/ruoyi/js/jquery-confirm.min.js}"></script>
<script th:inline="javascript">
    var sessionname = [[${session.username}]]
    var gsid = [[${session.gsid}]]
    $(document).ready(function () {
        if (gsid == null) {
            $.alert("当前状态未登陆系统或浏览器中当前会话结束了，您需要重新登陆","温馨提示")
            window.location.href = "/login";
        }

        // 获取当前日期
        function getCurrentMonthFirst() {
            var date = new Date();
            date.setDate(1);
            var month = parseInt(date.getMonth() + 1);
            var day = date.getDate();
            if (month < 10) {
                month = '0' + month
            }
            if (day < 10) {
                day = '0' + day
            }
            return date.getFullYear() + '-' + month + '-' + day;
        }

        function getCurrentMonthLast() {
            var date = new Date();
            var currentMonth = date.getMonth();
            var nextMonth = ++currentMonth;
            var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
            var oneDay = 1000 * 60 * 60 * 24;
            var lastTime = new Date(nextMonthFirstDay - oneDay);
            var month = parseInt(lastTime.getMonth() + 1);
            var day = lastTime.getDate();
            if (month < 10) {
                month = '0' + month
            }
            if (day < 10) {
                day = '0' + day
            }
            return date.getFullYear() + '-' + month + '-' + day;
        }

        initUserTable();
        $("#kssj").val(getCurrentMonthFirst())
        $("#jssj").val(getCurrentMonthLast())

        function initUserTable() {
            $("#bootstrap-table").bootstrapTable({
                toolbar: '#toolbar',
                showToggle: true,//是否切换显示
                showColumns: true,//是否显示列，
                showColumnsToggleAll: true,
                // detailView: true,//和下面的属性成对设置，是否显示加号显示详细信息
                // detailFormatter: "detailFormatter",
                showExport: true,//是否导出
                // showPaginationSwitch: true,//切换是否分页显示
                showFooter: true,//是否显示页脚，主要用途是显示汇总的信息
                striped: false,//是否显示行间隔色
                paginationPreText: '上一页',
                paginationNextText: '下一页',
                queryParamsType: '',
                method: 'GET',
                uniqueId: "id",
                exportDataType: "basic", //basic', 'all', 'selected'.
                // exportTypes:['Excel'],  //导出文件类型
                pageNumber: 'form' ? 1 : parseInt($('#_pageNumber').val()),
                pagination: true,//是否分页
                sidePagination: 'server',//server:服务器端分页|client：前端分页
                pageSize: 'form' ? 10 : parseInt($('#_pageSize').val()),//单页记录数
                pageList: [10, 20, 30, 'ALL'],//可选择单页记录数
                showRefresh: true,//刷新按钮
                queryParams: queryParams,
                // onDblClickRow: function (row,index) {
                //     console.log(index[0])
                // },
                url: "/sbgl/sbwhb/getwhjllist/",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'no',
                        title: '序号',
                        align: "center",
                        width: 60,
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {
                        field: 'whrq',
                        align: "center",
                        title: '日期'
                    },
                    {
                        field: 'bm',
                        align: "center",
                        title: '部门'
                    },
                    {
                        field: 'sbbh',
                        align: "center",
                        title: '设备编号'
                    },
                    {
                        field: 'gzyy',
                        align: "center",
                        title: '故障原因'
                    },
                    {
                        field: 'whjl',
                        align: "center",
                        title: '解决方案',
                        formatter: function (value, row, index) {
                            let values=row.jjfa;
                            if (values.indexOf("升级")!=-1){
                                values=value.substring(10,100);
                            }
                            var a = '<span>' + values + '</span>';
                            return a;
                        }
                    },
                    {
                        field: 'weihr',
                        align: "center",
                        title: '维护人员'
                    },
                    {
                        field: 'shiyr',
                        align: "center",
                        title: '使用人员'
                    }]
            })
        }
    });

    function queryParams(params) {
        var param = {
            limit: params.limit, // 页面大小
            offset: params.offset, // 页码
            nextPage: params.pageNumber,
            pageNumber: params.pageNumber,
            pageSize: params.pageSize,
            kssj: $("#kssj").val(),
            jssj: $("#jssj").val(),
            gsid: gsid,
        };
        return param;
    }

    //查询按钮事件
    $('#search_btn').click(function () {
        refresh()
        document.getElementById("pbid").style.display=""
        var miaos="计算机系统维护登记表"
        $("#bt").val(getwhxx(miaos)==""?"计算机系统维护登记表":getwhxx(miaos)[0].whmc)
        $("#wjh").val(getwhxx(miaos)==""?"":getwhxx(miaos)[0].wenh)
    });

    function refresh() {
        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;
        //获取当前是第几页
        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
        $("#_pageNumber").val(pageNumber);
        $("#_pageSize").val(pageSize);
        $('#bootstrap-table').bootstrapTable('refresh', {
            pageNumber: pageNumber,
            pageSize: pageSize,
        });
    }

    function removeTags(tagName,tagClass){
        var tagElements = document.getElementsByTagName( tagName );
        for( var m = 0 ; m < tagElements.length ; m++ ){
            if( tagElements[m].className == tagClass ){
                tagElements[m].parentNode.removeChild( tagElements[m] );
            }
        }
    }

    //维护记录打印
    function whjldy() {
        var kssj = $("#kssj").val()
        var jssj = $("#jssj").val()
        $('#tbody_id').empty();
        var linecount=$("#linecount").val()
        $.ajax({
            url: "/sbgl/sbwhb/getsbwhb/" + gsid + "/" + kssj + "/" + jssj,
            type: 'GET',
            async: false,
            success: function (data) {
                let pigxx=(682/linecount).toFixed(5)
                var tables = "";   //字符串拼接
                var j = 0;
                var whjl="";
                var kong = linecount-data.length%linecount
                for (var i in data) {  //遍历json数组
                    j = parseInt(i) + 1;
                    whjl=data[i].jjfa;
                    if (whjl.indexOf("升级")!=-1){
                        whjl=data[i].whjl.substring(10,100);
                    }
                    tables += "<tr style='font-family: 微软雅黑;font-size: 10px;'>"
                        + "<td align='center' class='xhtd'>" + j + "</td>"
                        + "<td align='center' class='rqtd'>" + data[i].whrq + "</td>"
                        + "<td align='center' class='bmtd'>" + data[i].bm + "</td>"
                        + "<td align='center' class='sbbhtd'>" + data[i].sbbh + "</td>"
                        + "<td align='center' class='gzyytd'>" + data[i].gzyy + "</td>"
                        + "<td align='center' class='jjfatd'>" + whjl + "</td>"
                        + "<td align='center' class='whrytd'>" + data[i].weihr + "</td>"
                        + "<td align='center' class='syrytd'>" + data[i].shiyr + "</td>"
                        + "<td align='center'>" + '' + "</td>"
                        + "</tr>";
                }
                for (let i = 0; i < kong; i++) {
                    tables += "<tr style='font-family: 微软雅黑;font-size: 10px;'>"
                        + "<td align='center' class='xhtd'>" + "</td>"
                        + "<td align='center' class='rqtd'>" + "</td>"
                        + "<td align='center' class='bmtd'>" + "</td>"
                        + "<td align='center' class='sbbhtd'>" + "</td>"
                        + "<td align='center' class='gzyytd'>" + "</td>"
                        + "<td align='center' class='jjfatd'>" + "</td>"
                        + "<td align='center' class='whrytd'>" + "</td>"
                        + "<td align='center' class='syrytd'>" + "</td>"
                        + "<td align='center'>" + '' + "</td>"
                        + "</tr>";
                }
                $('#tableid_sbtz').append(tables);
                var table = document.getElementById("tbody_id");
                table.style.height = pigxx+'px';
            }
        })
        // console.log($('#tableid_sbtz tr').children('td'))

        if($("#syrybox").is(':checked')==false){
            document.getElementById("syrytd").style.display="none"
            removeTags("td","syrytd");
        }
        if($("#xhbox").is(':checked')==false){
            document.getElementById("xhtd").style.display="none"
            removeTags("td","xhtd");
        }
        if($("#rqbox").is(':checked')==false){
            document.getElementById("rqtd").style.display="none"
            removeTags("td","rqtd");
        }
        if($("#bmbox").is(':checked')==false){
            document.getElementById("bmtd").style.display="none"
            removeTags("td","bmtd");
        }
        if ($("#sbbhbox").is(':checked')==false){
            document.getElementById("sbbhtd").style.display="none"
            removeTags("td","sbbhtd");
        }
        if($("#gzyybox").is(':checked')==false){
            document.getElementById("gzyytd").style.display="none"
            removeTags("td","gzyytd");
        }
        if($("#jjfabox").is(':checked')==false){
            document.getElementById("jjfatd").style.display="none"
            removeTags("td","jjfatd");
        }
        if($("#whrybox").is(':checked')==false){
            document.getElementById("whrytd").style.display="none"
            removeTags("td","whrytd");
        }
        if ($("#syrybox").is(':checked')) {
            document.getElementById("syrytd").style.display=""
            var syry=$("#syry").val()
            document.getElementById("syrytd").style.width=syry;
        }
        if ($("#xhbox").is(':checked')) {
            document.getElementById("xhtd").style.display=""
            var xh=$("#xh").val()
            document.getElementById("xhtd").style.width=xh;
        }
        if ($("#rqbox").is(':checked')) {
            document.getElementById("rqtd").style.display=""
            var rq=$("#rq").val()
            document.getElementById("rqtd").style.width=rq;
        }
        if ($("#bmbox").is(':checked')) {
            document.getElementById("bmtd").style.display=""
            var bm=$("#bm").val()
            document.getElementById("bmtd").style.width=bm;
        }
        if ($("#sbbhbox").is(':checked')){
            document.getElementById("sbbhtd").style.display=""
            var sbbh=$("#sbbh").val()
            document.getElementById("sbbhtd").style.width=sbbh;
        }
        if ($("#gzyybox").is(':checked')) {
            document.getElementById("gzyytd").style.display=""
            var gzyy=$("#gzyy").val()
            document.getElementById("gzyytd").style.width=gzyy;
        }
        if($("#jjfabox").is(':checked')) {
            document.getElementById("jjfatd").style.display=""
            var jjfa=$("#jjfa").val()
            document.getElementById("jjfatd").style.width=jjfa;
        }
        if ($("#whrybox").is(':checked')) {
            document.getElementById("whrytd").style.display=""
            var whry=$("#whry").val()
            document.getElementById("whrytd").style.width=whry;
        }
        var options = $('#divid_sbtz').html();
        var bt=$("#bt").val()
        var wjh=$("#wjh").val()
        LODOP = getLodop();
        LODOP.PRINT_INIT("");
        // LODOP.SET_PRINT_PAGESIZE(1,2970,2100,"");
        LODOP.ADD_PRINT_TEXT(15, 300, 220, 30, bt);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 15);
        LODOP.SET_PRINT_STYLEA(0, "bold", 1);
        LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
        LODOP.SET_PRINT_STYLEA(0, "Horient", 2);

        LODOP.ADD_PRINT_TEXT(38, 650, 180, 21, wjh);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
        LODOP.SET_PRINT_STYLEA(0, "Horient", 1);
        LODOP.SET_PRINT_STYLEA(0, "bold", 1);

        LODOP.ADD_PRINT_TABLE(50, 50, 2970, 2100, options);
        //循环取出表格中的数据，方式一
        // $('#tableid_sbtz tr').each(function(i){                   // 遍历 tr
        //     $(this).children('td').each(function(j){  // 遍历 tr 的各个 td
        //         // alert("第"+(i+1)+"行，第"+(j+1)+"个td的值："+$(this).text()+"。");
        //         LODOP.ADD_PRINT_TEXTA("neirong",10+i*21,10+j*flag,150,21,$(this).text());
        //         LODOP.SET_PRINT_STYLEA(0,"FontName","楷体");
        //         LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
        //     });
        // });
        //循环取出表格中的数据，方式二
        // var tb = document.getElementById('tableid_sbtz');    // table 的 id
        // var rows = tb.rows;                           // 获取表格所有行
        // for(var i = 0; i<rows.length; i++ ){
        //     for(var j = 0; j<rows[i].cells.length; j++ ){    // 遍历该行的 td
        //         // alert("第"+(i+1)+"行，第"+(j+1)+"个td的值："+rows[i].cells[j].innerHTML+"。");
        //         LODOP.ADD_PRINT_TEXTA("neirong",10+i*21,10+j*flag,150,21,rows[i].cells[j].innerHTML);
        //         LODOP.SET_PRINT_STYLEA(0,"FontName","楷体");
        //         LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
        //     }
        // }
        //bootstraptabale循环取出表格中的数据，方式三
        // var data = JSON.stringify($("#bootstrap-table").bootstrapTable('getData'));
        // var data_json = JSON.parse(data);
        // console.log(data_json)
        // for( var i=0;i<data_json.length;i++)
        // {
        //     LODOP.ADD_PRINT_TEXTA("neirong",10+i*21,10,"5%",21,i+1);
        //     LODOP.SET_PRINT_STYLEA(0,"FontName","楷体");
        //     LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
        //     LODOP.SET_PRINT_STYLEA(0,"border",1);
        //
        //     LODOP.ADD_PRINT_TEXTA("neirong",10+i*21,10+flag,"10%",21,data_json[i].whrq);
        //     LODOP.SET_PRINT_STYLEA(0,"FontName","楷体");
        //     LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
        //
        //     LODOP.ADD_PRINT_TEXTA("neirong",10+i*21,10+2*flag,"10%",21,data_json[i].bm);
        //     LODOP.SET_PRINT_STYLEA(0,"FontName","楷体");
        //     LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
        //
        //     LODOP.ADD_PRINT_TEXTA("neirong",10+i*21,10+3*flag,"10%",21,data_json[i].sbbh);
        //     LODOP.SET_PRINT_STYLEA(0,"FontName","楷体");
        //     LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
        //
        //     LODOP.ADD_PRINT_TEXTA("neirong",10+i*21,10+4*flag,"10%",21,data_json[i].gzyy);
        //     LODOP.SET_PRINT_STYLEA(0,"FontName","楷体");
        //     LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
        //
        //     LODOP.ADD_PRINT_TEXTA("neirong",10+i*21,10+5*flag,"30%",21,data_json[i].jjfa);
        //     LODOP.SET_PRINT_STYLEA(0,"FontName","楷体");
        //     LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
        //
        //     LODOP.ADD_PRINT_TEXTA("neirong",10+i*21,10+6*flag,"15%",21,data_json[i].weihr);
        //     LODOP.SET_PRINT_STYLEA(0,"FontName","楷体");
        //     LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
        //
        //     LODOP.ADD_PRINT_TEXTA("neirong",10+i*21,10+7*flag,"10%",21,data_json[i].shiyr);
        //     LODOP.SET_PRINT_STYLEA(0,"FontName","楷体");
        //     LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
        // }
        // LODOP.PRINT_DESIGN();
        LODOP.PREVIEW();
    };
    $("#reset").click(function () {
        var miaos="计算机系统维护登记表"
        $("#bt").val(getwhxx(miaos)==""?"计算机系统维护登记表":getwhxx(miaos)[0].whmc)
        $("#wjh").val(getwhxx(miaos)==""?"":getwhxx(miaos)[0].wenh)
        $("#xh").val("10mm")
        $("#rq").val("18mm")
        $("#bm").val("18mm")
        $("#sbbh").val("24mm")
        $("#gzyy").val("58mm")
        $("#jjfa").val("80mm")
        $("#whry").val("21mm")
        $("#syry").val("21mm")
    })

    function confirm(title,content,ele) {
        $.confirm({
            title: title,
            content: content,
            buttons: {
                确定: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function(){
                        $(ele).modal('hide');
                    }
                }
            }
        });
    }

    function getwhxx(miaos) {
        var shuju=""
        $.ajax({
            url: "/sbgl/wenhb/getlist/" + miaos+"/"+gsid,
            type: 'GET',
            async: false,
            success: function (data) {
                shuju=data
            },
        })
        return shuju
    }
</script>
</body>
</html>